<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>add</title>
    {js href='__STATIC__/layui/css/layui.css' /}
    {js href='__STATIC__/jquery/jquery-1.11.0.min.js' /}
    {js href='__STATIC__/layui/layui.all.js' /}
</head>
<style type="text/css">
    .main{width: 98%;margin: 0 auto;}
    .input{width: 60%}
</style>
<body>
<div class="main">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">真实姓名</label>
            <div class="layui-input-block">
                <input type="text" name="relname" placeholder="请输入真实姓名" autocomplete="off" class="layui-input input" lay-verify="required" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">微信openid</label>
            <div class="layui-input-block">
                <input type="text" name="openid" placeholder="请输入微信openid" autocomplete="off" class="layui-input input" lay-verify="required" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">刮刮乐拍照</label>
            <div class="layui-input-block">
                {:hook('Upload',['type'=>'image','name'=>'imgurl'])}
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">中奖金额</label>
            <div class="layui-input-block">
                <input type="text" name="balance" placeholder="请输入中奖金额" autocomplete="off" class="layui-input input" lay-verify="required|number">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-block">
                <input type="text" name="tel" placeholder="请输入电话" lay-verify="required|phone|number" autocomplete="off" class="layui-input input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formAdd">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formAdd)', function(data){
            let fd = data.field
            let imgurl = fd.imgurl
            if(imgurl===''){
                layer.msg('请上传图片')
                return false;
            }
            $.ajax({
                contentType: 'application/json',
                type: 'POST',
                url:"{$addUrl}",
                data:JSON.stringify(data.field),
                dataType:"json",
                success:msg=>{
                    if(msg.code===0){
                        layer.msg('添加成功',{icon: 6},()=>{
                            location.href="{$indexUrl}"
                        });
                    }else{
                        layer.msg('添加失败');
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>
